package com.cl.ks.entity;


import com.cl.ks.annotation.GenerateMVC;
import com.cl.mvc.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

@Entity
@Table(name = "ks_flow_graph")
@org.hibernate.annotations.Table(appliesTo = "ks_flow_graph", comment = "流程图表")
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@GenerateMVC
public class KsFlowGraph extends BaseEntity {
    @ApiModelProperty("名称")
    private String name;

    @ApiModelProperty("渲染JSON")
    @Column(columnDefinition = "longtext")
    private String graphJson;

    @ApiModelProperty("执行JSON")
    @Column(columnDefinition = "longtext")
    private String sparkNodeJson;

    @ApiModelProperty("父流程图id")
    private Integer parentId;
    @ApiModelProperty("用到的数据资源")
    private String ksDataTypeCodes;
    @ApiModelProperty("用到的规则")
    @Column(columnDefinition = "longtext")
    private String ruleIds;
    @ApiModelProperty("创建的表")
    @Column(columnDefinition = "longtext")
    private String createTables;
    @ApiModelProperty("用到的数据源")
    private String sourceConfigIds;

    @ApiModelProperty("变量JSON")
    @Column(columnDefinition = "longtext")
    private String variableJson;
    @ApiModelProperty("标签")
    private String tags;

    @ApiModelProperty("状态：-1 未上线，1上线，10运行中")
    private Integer status;

    @ApiModelProperty("原始数据量")
    @Column(columnDefinition = "int default 0")
    private Integer sourceConfigDataTotal = 0;
    @ApiModelProperty("规则结果数据量")
    @Column(columnDefinition = "int default 0")
    private Integer ruleDataTotal = 0;

    @ApiModelProperty("结果权限")
    private String resultPower;

    @ApiModelProperty("是否增量")
    private Boolean incrementFlag;

    @ApiModelProperty("执行失败的节点code")
    private String failedNodeCode;
    @Transient
    private SparkNode sparkNode;
    @Transient
    private Set<String> ksDataTypeCodeList = new TreeSet<>();
    @Transient
    private Set<String> ruleIdList = new TreeSet<>();
    @Transient
    private Set<String> sourceConfigIdList = new TreeSet<>();
    @Transient
    private Set<String> createTableList = new TreeSet<>();
    @Transient
    private Integer ksFlowTaskId;
    @Transient
    private Boolean taskFlag = false;
    @Transient
    private Boolean testFlag = false;
    @Transient
    private Boolean childGraphFlag = false;
    @Transient
    private Boolean saveKsFlowResultFlag = true;
    @Transient
    private String auth;


    @OneToMany(mappedBy = "ksFlowGraph", cascade = CascadeType.REMOVE)
    @JsonIgnoreProperties({"ksFlowGraph","ksFlowTask", "ksFlowGraphLogList", "ksFlowResultList"})
    @OrderBy("id desc")
    @ApiModelProperty("记录列表")
    @ToString.Exclude
    private List<KsFlowGraphRecord> ksFlowGraphRecordList = new ArrayList<>();


    @Override
    public String toString() {
        return "KsFlowGraph{" +
                "name='" + name + '\'' +
                ", graphJson='" + graphJson + '\'' +
                ", sparkNodeJson='" + sparkNodeJson + '\'' +
                ", parentId=" + parentId +
                ", ksDataTypeCodes='" + ksDataTypeCodes + '\'' +
                ", ruleIds='" + ruleIds + '\'' +
                ", createTables='" + createTables + '\'' +
                ", sourceConfigIds='" + sourceConfigIds + '\'' +
                ", tags='" + tags + '\'' +
                ", status=" + status +
                ", sourceConfigDataTotal=" + sourceConfigDataTotal +
                ", ruleDataTotal=" + ruleDataTotal +
                ", resultPower='" + resultPower + '\'' +
                ", incrementFlag=" + incrementFlag +
                ", childGraphFlag=" + childGraphFlag +
                ", ksDataTypeCodeList=" + ksDataTypeCodeList +
                ", ruleIdList=" + ruleIdList +
                ", sourceConfigIdList=" + sourceConfigIdList +
                ", createTableList=" + createTableList +
                ", ksFlowTaskId=" + ksFlowTaskId +
                ", taskFlag=" + taskFlag +
                ", testFlag=" + testFlag +
                ", auth='" + auth + '\'' +
                '}';
    }
}
